class Solution {
public:
    string countAndSay(int n) {
        string ret = "1", tmp = "";
        int cnt = n;
        while(--cnt) // 解释n-1次
        {
            int len = ret.size();
            tmp = "";
            for(int left = 0, right = 0; right < len; left = right)
            {
                while(right < len && ret[left] == ret[right])
                {   // 双指针计算个数
                    ++right;
                }
                tmp += to_string(right - left);
                tmp += ret[left];
            }
            ret = tmp;
        }
        return ret;
    }
};